package org.csu.mypetstorecmsapi.persistence;

import jakarta.transaction.Transactional;
import org.csu.mypetstorecmsapi.domain.Item;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ItemDao extends JpaRepository<Item, Integer> {

    @Transactional
    @Modifying
    @Query(value = "delete from item where productid =?1", nativeQuery = true)
    void deleteByProductId(String productId);

    @Modifying
    @Query(value = "select * from item where productid =?1", nativeQuery = true)
    List<Item> findByProductId(String productId);
}
